﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FancyBattles.GameEntities;
using FancyBattles.GameMind;

namespace FancyBattles.GameScreen.StateMachine
{
    class BallRageState : State
    {        
        public const float DESACCELARATION_RATE = -0.002f;

        public BallRageState(GameplayScreen parentScreen)
            : base(parentScreen, PlayerIndex.One)
        {
            Overmind overmind = new Overmind();
            foreach (BouncingBitch bitch in BouncingBitch.BitchesList)
            {
                if (bitch.Player == PlayerIndex.Two && parentScreen.IsSinglePlayer())
                {
                    try
                    {
                        bitch.Speed = overmind.Handle(bitch, BouncingBitch.BitchesList);
                        if (bitch.GetType() == typeof(Archer))
                        {
                            Arrow newArrow = new Arrow(overmind.HandleArrow(bitch, BouncingBitch.BitchesList), bitch);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    bitch.IsConfirmed = false;
                    bitch.IsSelected = false;
                }
                bitch.Acceleration = DESACCELARATION_RATE;
                bitch.ChangeTexture(BouncingBitch.animationState.Action);
            }
        }
        
        public override void Update(GameTime gameTime)
        {
            if ((from bitch in BouncingBitch.BitchesList where bitch.Speed != Vector2.Zero select bitch).Count() == 0)
            {
                ParentScreen.AltState = new TransitionState(ParentScreen);
            }

            BouncingBitch.UpdateBitches();
            foreach (BouncingBitch b in (from bitch in BouncingBitch.BitchesList where bitch.Health <= 0 select bitch).ToList())
            {
                b.Die();
            }
            Arrow.UpdateArrows();
        }

        public override void Draw(GameTime gameTime)
        {
        }
    }
}
